import tools from "@/common/tools.js";
import {
	post
} from '@/common/axios.js';
import {
	addUserAdvantage, //添加个人优势
	removeUserAdvantage, //删除优势
	getuserCenter //用户动态
} from '@/common/path.js'
export default {
	namespaced: true,
	state: {
		userInfo: uni.getStorageSync('userInfo'),
		userActiveList: [], //用户动态
	},
	getters: {

	},
	mutations: {
		SET_LIST(state, data) {
			state.userActiveList = data
		},
	},
	actions: {
		// 主页 - 添加优势
		getphotoWallApi({
			dispatch,
			commit,
			state
		}, args = {}) {
			if (args.advantage == '') {
				tools.showToast('填写为空')
				return
			}
			post(addUserAdvantage, args).then(res => {
				tools.showToast(res.msg)
				if (res.code == 0) {
					setTimeout(() => {
						tools.back();
					}, 1000)
				}
			})
		},
		//主页- 个人优势删除
		removeUserAdvantage({
			dispatch,
			commit,
			state
		}, args = {}) {
			post(removeUserAdvantage, args).then(res => {
				tools.showToast(res.msg)
				if (res.code == 0) {
					setTimeout(() => {
						tools.back();
					}, 1000)
				}
			})
		},
		//用户动态
		getuserCenter({
			dispatch,
			commit,
			state
		}, args = {}) {
			post(getuserCenter, args).then(res => {
				if (res.code == 0) {
					if (args.pageNum == 1) {
						commit('SET_LIST', res.data.moments)
					}else{
						state.userActiveList.push(...res.data.moments)
						commit('SET_LIST', state.userActiveList)
					}
				}
			})
		},
	},
}
